package applets;
import java.awt.*;
import java.awt.event.*;

import java.applet.*;

import algorithms.Beaufort;
import algorithms.Key;


public class BeaufortApplet extends Applet implements ActionListener{

    /**
     * serial ID
     */
    private static final long serialVersionUID = -4316982731468739714L;

    TextField inputLine = new TextField(15);
    TextField inputLine2 = new TextField(15);
    TextField inputLine3 = new TextField(15);
    
    Beaufort beaufort = new Beaufort();
    
    public BeaufortApplet() {
        add(inputLine);
        add(inputLine2);
        add(inputLine3);
        inputLine.addActionListener(this);
        inputLine2.addActionListener(this);
        inputLine3.addActionListener(this);
        inputLine.setText("plain letter e.g. K");
        inputLine2.setText("beaufort shiting e.g. 8");
        inputLine3.setText("cipher letter");
    }
    
    public void actionPerformed(ActionEvent event) {
        String sChar = inputLine.getText();
        String sBeaufort = inputLine2.getText();
        Key givenKey= Key.charToKey(sChar.charAt(0));
        int givenBeaufort = Integer.parseInt(sBeaufort);
        String sResult = Beaufort.getResultingLetterEncrypt(givenKey, givenBeaufort).toString();
        inputLine3.setText(sResult);
    } 

}
